home *** CD-ROM | disk | FTP | other *** search
- Path: wittgenstein.flingern.de!not-for-mail
- From: mackenb@uni-duesseldorf.de (Georg Mackenbrock)
- Newsgroups: comp.lang.c++
- Subject: how to use fstreams
- Date: 3 Mar 1996 22:30:06 GMT
- Organization: home
- Message-ID: <4hd6he$49c@wittgenstein.flingern.de>
- NNTP-Posting-Host: modem8.rz.uni-duesseldorf.de
- Keywords: streams
- X-Newsreader: TIN [UNIX 1.3 BETA-950824-color PL0]
-
- Consider the following C-code:
-
- #include <g++/fstream.h>
-
- int main(void)
- {
- ofstream out("stream");
- int i=10,j=20,k=30;
-
- out.setf(ios::bin);
- out<<i<<j<<k; // (7)
- out.flush();
-
- ifstream in("stream");
- in.setf(ios::bin);
- in>>i>>j>>k; // (12)
- cout<<"i: "<<i<<" j: "<<j<<" k:"<<k<<"\n"; // (13)
- }
-
- Why is the output in (13): i: 102030 j: 20 k:30 and not i: 10 j: 20 k: 30 ?
- ==================== =================
-
- Using setf(ios::bin) should put the stream in binary-mode? Or is it not
- possible to use "<<" to produce binary files?
-
- BTW, I know that I get the correct output, if line (7) is replaced by:
-
- (7') out<<i<<" "<<j<<" "<<k;
-
- but the stream is still a text-stream.
-
- Georg.
-
- (Mail: mackenb@uni-duesseldorf.de)
-